<?php

#namespace Giocondo;

# text -- A widget for multi line formatted text editing.
class Text extends Widget {
	protected $options = array(
		'editable'  => 1,
		'sensitive' => 1
	);

	protected $text = '';

	public function __construct($options = array()) {
		parent::__construct($options);
	}

	public function setValue($value) {
		$this->text = $value;
		return FALSE;
	}

	# TODO: $index is ignored
	public function insert($index, $text) {
		$this->text .= $text;
	}

	# TODO: parameters are ignored
	public function get($startIndex, $endIndex = 'end') {
		return $this->text;
	}

	public function display($options=array()) {
		# Attach hidden event to update value.
		parent::display(array('onChanged' => sprintf('e(%u,1);', $this->id)));

		# TODO: dimensions are not configured (they should be setted in order to 
		# the XHTML document to validate).
		XHtml::element('textarea', $this->text, array(
			'id'       => $this->id,
			'rows'     => 4,
			'cols'     => 6,
			'disabled' => $this->options['sensitive'],
			'readonly' => $this->options['editable']
		));
	}
}

# End of file
# vim: set ts=2 sw=2 noet:
?>
